package o;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.text.TextUtils;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.lang.ref.SoftReference;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Locale;
import java.util.WeakHashMap;
import o.dky.d;
import o.dky.j;

public final class epw {
    private static WeakHashMap<Long, SoftReference<String>> ॱ = new WeakHashMap();

    public static String ˊ(long j) {
        Context ˋ = ContentManager.getInstant().getContext();
        if (j == 0) {
            return ˋ.getString(j.ʽᐝ, new Object[]{"0"});
        }
        SoftReference softReference = (SoftReference) ॱ.get(Long.valueOf(j));
        if (softReference != null && softReference.get() != null) {
            return (String) softReference.get();
        }
        String string;
        DecimalFormat decimalFormat = null;
        String str = "";
        if (j > 104857) {
            decimalFormat = new DecimalFormat("###.#");
        } else if (j > 10485) {
            decimalFormat = new DecimalFormat("###.##");
        }
        if (decimalFormat != null) {
            double d = (((double) j) / 1024.0d) / 1024.0d;
            string = ˋ.getString(j.ʽᐝ, new Object[]{decimalFormat.format(d)});
        } else {
            string = ˋ.getString(j.ʽᐝ, new Object[]{"0.01"});
        }
        ॱ.put(Long.valueOf(j), new SoftReference(string));
        return string;
    }

    public static double ˋ(long j) {
        double d = 10.0d;
        if (j == 0) {
            return 0.0d;
        }
        if (j <= 104857 && j > 10485) {
            d = 100.0d;
        }
        return ((double) Math.round(((((double) j) / 1024.0d) / 1024.0d) * d)) / d;
    }

    public static String ˊ(double d) {
        double d2 = 10.0d;
        Context ˋ = ContentManager.getInstant().getContext();
        if (Math.abs(d - 0.0d) < 1.0E-6d) {
            return ˋ.getString(j.ʽᐝ, new Object[]{"0"});
        }
        DecimalFormat decimalFormat = null;
        String str = "";
        if (d - 0.1d > 1.0E-6d) {
            decimalFormat = new DecimalFormat("###.#");
        } else if (d - 0.01d > 1.0E-6d) {
            d2 = 100.0d;
            decimalFormat = new DecimalFormat("###.##");
        }
        d2 = ((double) Math.round(d * d2)) / d2;
        if (decimalFormat != null) {
            return ˋ.getString(j.ʽᐝ, new Object[]{decimalFormat.format(d2)});
        }
        return ˋ.getString(j.ʽᐝ, new Object[]{"0.01"});
    }

    public static String ˊ(long j, long j2) {
        return ˊ(j) + " / " + ˊ(j2);
    }

    public static String ॱ(Context context, int i, Object... objArr) {
        return String.format(Locale.ENGLISH, context.getResources().getString(i), objArr);
    }

    public static void ˎ(Context context) {
        try {
            Intent intent = new Intent("huawei.intent.action.HSM_WIDGET_ONKEY_CLEAN");
            intent.setPackage("com.huawei.systemmanager");
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Logger.e("Utils", "cleanMemory ActivityNotFoundException " + e.toString());
        } catch (SecurityException e2) {
            Logger.e("Utils", "cleanMemory SecurityException " + e2.toString());
        }
    }

    public static String ˊ(String str, String str2) {
        try {
            return (String) Class.forName("android.os.SystemProperties").getMethod("get", new Class[]{String.class, String.class}).invoke(null, new Object[]{str, str2});
        } catch (Throwable e) {
            Logger.ˋ("Utils", "Exception while getting system property: ", e);
            return str2;
        }
    }

    public static boolean ॱ() {
        return ˊ("ro.carrier", "").equals("wifi-only");
    }

    public static boolean ॱ(Context context, String str) {
        if (context == null || TextUtils.isEmpty(str)) {
            return false;
        }
        List runningTasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
        if (!(runningTasks == null || runningTasks.isEmpty())) {
            Object packageName = ((RunningTaskInfo) runningTasks.get(0)).topActivity.getPackageName();
            if (!TextUtils.isEmpty(packageName) && packageName.equals(str)) {
                return true;
            }
        }
        return false;
    }

    public static double ˋ(double d, int i) {
        return new BigDecimal(d).setScale(i, 1).doubleValue();
    }

    public static PackageInfo ˊ(PackageManager packageManager, String str) {
        PackageInfo packageInfo = null;
        if (!(packageManager == null || dof.ॱ(str))) {
            try {
                packageInfo = packageManager.getPackageInfo(str, DnsConfig.MAX_CACHE_ENTRIES);
            } catch (NameNotFoundException e) {
                Logger.ˋ("Utils", "Utils error is: " + e);
            }
        }
        return packageInfo;
    }

    public static boolean ˋ() {
        return ˎ() || ʻ();
    }

    private static boolean ˎ() {
        String ˊ = ˊ("ro.product.board", "");
        String ˊ2 = ˊ("ro.product.name", "");
        String ˊ3 = ˊ("ro.build.characteristics", "");
        if ((("MediaPad".equalsIgnoreCase(ˊ2) || "SpringBoard".equalsIgnoreCase(ˊ2)) && (ˊ.contains("s7") || ˊ.contains("s10") || ˊ.contains("S7") || ˊ.contains("S10"))) || "tablet".equalsIgnoreCase(ˊ3)) {
            return true;
        }
        ˊ = ˊ("ro.product.model", "");
        if ("Ideos S7".equalsIgnoreCase(ˊ) || "S7".equalsIgnoreCase(ˊ)) {
            return true;
        }
        return false;
    }

    private static boolean ʻ() {
        try {
            return ((Boolean) Class.forName("com.huawei.pad.Product").getMethod("isTablet", new Class[0]).invoke(null, new Object[0])).booleanValue();
        } catch (NoSuchMethodException e) {
            Logger.ˎ("Utils", "isTablet exception");
            return false;
        } catch (ClassNotFoundException e2) {
            Logger.ˎ("Utils", "isTablet exception");
            return false;
        } catch (IllegalAccessException e3) {
            Logger.ˎ("Utils", "isTablet exception");
            return false;
        } catch (IllegalArgumentException e4) {
            Logger.ˎ("Utils", "isTablet exception");
            return false;
        } catch (InvocationTargetException e5) {
            Logger.ˎ("Utils", "isTablet exception");
            return false;
        }
    }

    public static boolean ˏ() {
        Context ˋ = ContentManager.getInstant().getContext();
        if (ˋ == null || ˋ.getResources() == null || ˋ.getResources().getColor(d.ˉ) == -16777216) {
            return false;
        }
        return true;
    }

    public static int ˊ() {
        return ContentManager.getInstant().getContext().getResources().getColor(d.ॱॱ) & 16777215;
    }
}
